package InetProgram;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;

public class UdpReceive {
    public static void main(String[] args) throws IOException {
        receiveData();
    }

    public static void receiveData() throws IOException {
        DatagramSocket ds = new DatagramSocket(10086);
        byte[] bytes = new byte[1024];
        DatagramPacket dp = new DatagramPacket(bytes, bytes.length);
        while (true) {
            ds.receive(dp);
            byte[] data = dp.getData();
            InetAddress address = dp.getAddress();
            int length = dp.getLength();
            int port = dp.getPort();

            System.out.println("接收到来自" + address + "的" + port + "端口的数据:");
            System.out.println(new String(data, 0, length));
        }
    }

}
